/*
 ------------------------------------------------------------------------------
 Copyright (C) 2013 Eternal Games.

 This file is part of the GLQuake source code.

 The GLQuake source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The GLQuake source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the GLQuake source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


//
// defManager.h - framework used by dynamic-link libraries
//


#ifndef __FRAMEWORK_DEFMANAGER_H__
#define __FRAMEWORK_DEFMANAGER_H__


/*
 ==============================================================================

 Definition Manager:

 A definition is a text data type that defines the properties and behaviour of
 certain aspects of the game, such as surface materials or sound effects.

 All "small text" data types, like tables, skins, materials, sound shaders,
 etc, are managed uniformly, allowing reloading, purging, enumerating, listing,
 printing, etc.
 All "large text" data types that never have more than one definition in a
 given file, like maps, GUIs, etc, are not handled here.

 During definition parsing, errors should never be issued, only warnings. A
 default definition should always be used in place of a bad definition.

 ==============================================================================
*/

enum defType_t {
	DEF_TABLE,
	DEF_SKIN,
	DEF_MATERIAL,
	DEF_SOUNDSHADER,
	DEF_ANIMATION,
	DEF_WEAPON,
	DEF_PARTICLE,
	DEF_FX,

	// New definition types can be added here

	DEF_MAX_TYPES			= 32
};

struct defData_t {
	char					name[MAX_PATH_LENGTH];

	bool					referenced;

	char *					textString;
	int						textLength;

	char					sourceFile[MAX_PATH_LENGTH];
	int						sourceLine;

	defData_t *				nextHash;
};

// Functions exported by the engine
struct glqDefManager_t {
	// Registers a definition type
	void					(*RegisterType)(defType_t type, const char *typeName, const char *filePath, const char *fileExtension, const char *listCommand, const char *printCommand);

	// Loads all the definitions of the given type
	void					(*LoadDefs)(defType_t type, bool print);

	// Purges all the definitions of the given type
	void					(*PurgeDefs)(defType_t type);

	// Enumerates all the definitions of the given type using a callback
	void					(*EnumDefs)(defType_t type, void (*callback)(const char *name));

	// Returns the number of definitions of the given type
	int						(*GetNumDefs)(defType_t type);

	// Returns a definition of the given type with the given index. Returns
	// NULL if the index is out of range.
	defData_t *				(*GetDefByIndex)(defType_t type, int index);

	// Finds a definition of the given type with the given name. Returns NULL
	// if not found.
	defData_t *				(*FindDef)(defType_t type, const char *name);
};


#endif	// __FRAMEWORK_DEFMANAGER_H__